package com.mrjy.maintain.bo;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.mrjy.common.entity.MenuInfo;
import com.mrjy.maintain.dao.IMenuInfoDao;
import com.mrjy.maintain.dao.IRoleMenuDao;

@Service("adminAuthorityBo")
public class AdminAuthorityBo implements IAdminAuthorityBo {
	
	@Resource
	private IMenuInfoDao menuInfoDao;
	@Resource
	private IRoleMenuDao roleMenuDao;

	@Override
	public Object validateAuthToPath(Integer roleId, String requestURI) {
		Map<String, Object> map = new HashMap<String, Object>();
		//Vue 路由的最后一个path值
		String path = requestURI.substring(requestURI.lastIndexOf("/")+1);
		MenuInfo menuInfo =  (MenuInfo) menuInfoDao.queryByMenuUrl(path);
		if(null == menuInfo){
			map.put("err_code", "40001");
			map.put("err_msg", "菜单信息不存在");
			return map;
		}
		
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("roleId", roleId);
		paramMap.put("menuId", menuInfo.getId());
		Boolean matchFlag = roleMenuDao.isMatchByUser(paramMap);
		if(matchFlag){
			map.put("err_code", "200");
			map.put("err_msg", "权限匹配");
			return map;
		}else{
			map.put("err_code", "4002");
			map.put("err_msg", "权限不匹配");
			return map;
		}
	}
}
